import 'package:dss_base/dss_base.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 对话框改变状态
enum LoadingDialogState { init, show, hide }

/// 全局的 loading 对话框
Widget loadingDialog = Center(
  child: Container(
    width: 100.w,
    height: 100.w,
    decoration: const BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.all(Radius.circular(10)),
    ),
    padding: EdgeInsets.all(20.w),
    child: const CircularProgressIndicator(),
  ),
);

Widget loadingDialogLand = Center(
  child: Container(
    width: 100,
    height: 100,
    decoration: const BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.all(Radius.circular(10)),
    ),
    padding: EdgeInsets.all(20),
    child: const CircularProgressIndicator(),
  ),
);

/// 页面状态
enum PageState {
  initState,
  loadingState,
  successState,
  failureState,
  emptyState,
}

/// 页面状态视图
class PageStateHolder {
  PageStateHolder._();

  static final PageStateHolder _singleton = PageStateHolder._();

  factory PageStateHolder() => _singleton;

  static PageStateHolder get instance => _singleton;

  Widget initStatePage = const Center(child: CircularProgressIndicator());

  Widget loadingStatePage = const Center(child: CircularProgressIndicator());

  Widget createLoadingStatePage() => Container(
    alignment: Alignment.center,
    padding: EdgeInsets.all(50.w),
    child: loadingStatePage,
  );

  Widget createFailureStatePage() => Container(
    alignment: Alignment.center,
    padding: EdgeInsets.all(50.w),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        ImageX(urlOrPath: 'dss_base/ic_page_empty.webp'),
        SizedBox(height: 10),

        Text(
          'Error',
          style: TextStyle(fontSize: 18.sp, color: Colors.black),
        ),
      ],
    ),
  );

  Widget createEmptyStatePage() => Container(
    alignment: Alignment.center,
    padding: EdgeInsets.all(50.w),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        ImageX(urlOrPath: 'dss_base/ic_page_empty.webp'),
        SizedBox(height: 10),
        Text(
          'No data',
          style: TextStyle(fontSize: 18.sp, color: Colors.black),
        ),
      ],
    ),
  );
}
